﻿function Get-TSMArchiveCopyGroup {    
    <#
        .SYNOPSIS
            Get TSM archive copy group
                    
        .DESCRIPTION
            The Get-TSMArchiveCopyGroup returns copy groups

        .EXAMPLE
            Get-TSMArchiveCopyGroup

        .NOTES
            Contributors:  David Seibel
            Last Revision Date: 09/01/2015

    #>
    [CmdletBinding()]
    Param(
        [Parameter(Position = 0)]
        $Domain,
        
        [Parameter(Position = 1)]
        $PolicySet,
        
        [Parameter(Position = 2)]
        $ManagementClass,
        
        [Parameter(Position = 3)]
        $CopyGroup
    )  

    $whereProps = @()
    $whereProps += [PSCustomObject]@{ "Column" = "DOMAIN_NAME";    "Operator" = "LIKE"; "Value" = $Domain }
    $whereProps += [PSCustomObject]@{ "Column" = "SET_NAME";       "Operator" = "LIKE"; "Value" = $PolicySet }
    $whereProps += [PSCustomObject]@{ "Column" = "CLASS_NAME";     "Operator" = "LIKE"; "Value" = $ManagementClass }
    $whereProps += [PSCustomObject]@{ "Column" = "COPYGROUP_NAME"; "Operator" = "LIKE"; "Value" = $CopyGroup }

    $query = Format-TSMQuery -Table "AR_COPYGROUPS" -Where $whereProps -OrderBy "DOMAIN_NAME,SET_NAME,CLASS_NAME,COPYGROUP_NAME"
    $result = Invoke-TSMCommand -Command $query
    
    $defaultDisplaySet = 'DOMAIN_NAME','SET_NAME','CLASS_NAME','COPYGROUP_NAME','RETVER'
    $typeDefinitions = @{
                        "CHG_TIME" = [DateTime]
                        }

    return Format-TSMData -Data $result -TypeDefinitions $typeDefinitions -DefaultDisplaySet $defaultDisplaySet
}